var indexs = new Vue({
    el: '#indexs',
    //初始化数据类型
    data: {
        //成交总价
        totalMoney :0,
        //市场总价
        bazaarMoney :0,
        //节省资金
        spare :0,
        //数据统计信息
        option : {
            title : {
                text: '平台数据统计',
                subtext: '价格对比图'
            },
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data:['市场价','成交价']
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : []
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [


            ]
        },
        //饼状图数据
        optionPie: {
            title: {
                text: '平台各类商品信息购买情况',
                subtext: '饼状图',
                x: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: []
            },
            series: [
                {
                    name: '成交金额（元）',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: [

                    ],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        },
        userinfo: {},
        LoginUser: {},
        pwd: {},
        User: [],
        //用户角色信息
        userRole: {},
        //商家信息
        merchants: [],

        //预警显示
        warnList:[],
        //待办事项
        strs:{
            sqNum:'',
            dshNum:'',
            dxjNum:'',
            dbjNum:'',
            dqrNum:'',
            htNum:'',
            tzsNum:'',
            dwcNum:'',
            dshsjNum:'',
            zsNum:''
        },
        pagesize:'5',
        currentPage:'1',

    },
    //时间提交方法
    methods: {
        //预警信息分页（总条数）
        handleSizeChange:function(size){
            var _this = this;
            _this.pagesize = size;
        },
        ////预警信息分页（当前页）
        handleCurrentChange:function(currentPage){
            var _this = this;
            _this.currentPage = currentPage;
        },
        handleOpen:function(key, keyPath) {
           /* console.log(key, keyPath);*/
        },
        handleClose:function(key, keyPath) {
           /* console.log(key, keyPath);*/
        },

        //跳转到商家信息
        companyInformation: function () {
            $.post("/home/commodity/selectMerchant", "", function (data) {
                $("#wrap-left").load("http://" + window.location.host + "/person/businessmen.html", function () {
                    businessmen.merchantList = data.data.merchantList;

                });
            });
        },
        //跳转到管理中心
        manageIndex:function(){
            window.location.reload();
        },
        //添加采购单清单
        addPurchaseOrdesdetail: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/addPurchaseOrdesdetail.html", function () {

            });
        },
        //跳转采购单清单列表
        queryPurchaseDetailList: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseDetailListQuery.html", function () {

            });
        },

        //采购确认书
        resultValidation: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/resultValidation.html", function () {

            });
        },
        //打印合同
        memorandumInUniting: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/memorandumInUnitingList.html", function () {

            });
        },
        //询价单
        personOffers: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/personOffers.html", function () {

            });
        },
        //询价单结果
        personOffersList: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/personOffersList.html", function () {

            });
        },
        //加载商家审批信息
        shopEnterExamine: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/shopEnterExamine.html", function () {

            });
        },
        //加载采购单审批信息
        purchaseOrdersEnterExamine: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseDetailListEnterByParent.html", function () {

            });
        },
        //加载采购单询价信息
        purchaseOrdersQuotation: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseDetailList4.html", function () {

            });
        },
        //加载采购单询价信息
        queryPurchaseAndOrdesdetail: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/QueryPurchaseAndOrdesdetail.html", function () {

            });
        },
        //加载采购单完成信息
        purchaseOrdersEnter: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/purchaseOrderEnter.html", function () {

            });
        },
        //加载采购单完成信息
        addressManagerList: function () {
            $("#wrap-left").load("http://" + window.location.host + "/home/addressManagerList.html", function () {

            });
        },
        //查看统计报表
        statistical: function (type) {
            $("#wrap-left").load("http://" + window.location.host + "/home/statisticalChart.html", function () {
                statisticalChart.type = type;
                $.post("/home/order/presentUser",
                    "",
                    function (data) {
                    var goodtypes =  data.data.goodsType;
                    /*采购办统计采购单位*/
                    if(type==1){
                        for (var i = 0; i < data.data.unit.length; i++) {
                            var map = {};
                            map.value = data.data.unit[i].id;
                            map.label = data.data.unit[i].name;
                            statisticalChart.options.push(map);
                        }
                        statisticalChart.userUnit = data.data.unit;
                    }
                    /*采购办统计商家信息*/
                    if(type==0){
                        for (var i = 0; i < data.data.merchant.length; i++) {
                            var map = {};
                            map.value = data.data.merchant[i].id;
                            map.label = data.data.merchant[i].companyName;
                            statisticalChart.options.push(map);
                        }
                        statisticalChart.userUnit = data.data.merchant;
                    }
                    /*采购单位统计信息*/
                    if(type==2){
                        for (var i = 0; i < goodtypes.length; i++) {
                            var map = {};
                            map.value = goodtypes[i].id;
                            map.label = goodtypes[i].name;
                            statisticalChart.options.push(map);
                        }
                        statisticalChart.userUnit = data.data.unit;
                    }
                    /*商家统计信息*/
                    if(type==3){
                        for (var i = 0; i < goodtypes.length; i++) {

                            var map = {};

                            map.value = goodtypes[i].id;

                            map.label = goodtypes[i].name;

                            statisticalChart.options.push(map);

                        }
                        statisticalChart.userUnit = data.data.merchant;
                    }
                    statisticalChart.goodsType = data.data.goodsType;

                    });
            });
        },
        //附件上传
        submitExcel:function(){
            var _this = this;
            var excelFile = $("#excelFile").val();
            if(excelFile=='') {alert("请选择需上传的文件!");}
            if(excelFile.indexOf('.xls')==-1){alert("文件格式不正确，请选择正确的Excel文件(后缀名.xls)！");}
            $("#fileUpload").submit();
        },

        statistics: function () {
            $("#statistics").load("http://" + window.location.host + "/home/statisticalChart.html", function () {

            });
        },
        //跳转到用户管理
        onUser: function () {
            var _this = this;
            debugger
            $("#wrap-left").load("http://" + window.location.host + "/person/useradmin.html", function () {
                $.post("/sys/user/userRoleSelect", "", function (data) {
                    //12角色为采购单位
                    var UserRole = data.data.SysUserRole;
                    //角色信息
                    var SysRole = data.data.sysRole;
                    var der = [];
                    for (var i = 0; i < UserRole.length; i++) {
                        for (var j = 0; j < _this.User.length; j++) {
                            if(_this.User[j].createBy == _this.LoginUser.id && UserRole[i].sysUserId == _this.User[j].id){
                                der.push(_this.User[j]);
                                useradmin.userInformation = der;
                            }


                        }
                    }


                });
            });
        },
        //公告信息
        onNotice: function () {
            var _this = this;
            debugger
            $("#wrap-left").load("http://" + window.location.host + "/person/notice.html", function () {
                $.post("/home/notice/select", "", function (data) {
                    notice.noticeList = data.data.noticelist;
                });

            });
        },
        //修改密码
        updatePwd: function () {
            var _this = this;
            $.post("/sys/user/updatePwdVerify", {
                "pwd": _this.pwd.original,
                "originalPwd": _this.LoginUser.password
            }, function (data) {
                var see = data.data.pwdResult;
                if (see) {
                    $.post("/sys/user/updatePwd", {"NewPwd": _this.pwd.new}, function (data) {
                        if (data.data.pwd1 == 1) {
                            _this.$message({
                                message: '恭喜你，密码已修改!',
                                type: 'success'
                            });
                        } else {
                            _this.$message({
                                message: '警告哦，密码修改失败!',
                                type: 'warning'
                            });
                        }
                    });
                }

            });

        },

    },
    //页面加载完成后执行此方法
    created: function () {
        var _this = this;
        //查询登录用户
        $.post("/sys/user/selectLoginUser", "", function (data) {
            _this.LoginUser = data.data.loginuser;
            _this.userRole = data.data.userRole[0];
            _this.merchants = data.data.merchants;
        });
        //查询用户信息
        $.post("/sys/user/selectUser", "", function (data) {
            _this.User = data.data.sysUser;
        });

        //预警信息
        $.post("/home/warnInfo/selectStatistics", "", function (data) {
            _this.warnList = data.data.warnText;
            /*if(data.data.warnText.length==0){
                $("#warnInfo").css("display","none");
            }*/
        });

        //统计信息
        $.post("/home/order/statisticsData", "", function (data) {
            if(data.code == 200){
                debugger
                var statisticsData = data.data.statisticsData;
                _this.totalMoney = data.data.totalMoney;
                _this.bazaarMoney = data.data.bazaarMoney;
                _this.spare = Number(_this.bazaarMoney) - Number(_this.totalMoney);

                var total=[];
                var bazaar = [];
                var xAxis = [];
                for(var key in statisticsData){
                    var lpi = {};
                    lpi.value=  statisticsData[key].totalMoney;
                    lpi.name =key;
                    _this.optionPie.series[0].data.push(lpi);
                    xAxis.push(key)
                    total.push(statisticsData[key].totalMoney);
                    bazaar.push(statisticsData[key].bazaarMoney);
                }

                _this.option.xAxis[0].data= xAxis;

                _this.optionPie.legend.data = xAxis;

                for(var i=0;i<2;i++){
                    var pp={};



                        pp.type ='bar';
                    if(i==0) {
                        pp.name = '市场价';
                        pp.data = bazaar;
                    }else{
                        pp.name = '成交价';
                        pp.data = total;
                    }
                        pp.markPoint = {
                            data : [
                                {type : 'max', name: '最大值'},
                                {type : 'min', name: '最小值'}
                            ]
                        };
                        pp.markLine = {
                            data : [
                                {type : 'average', name: '平均值'}
                            ]
                        };

                    _this.option.series.push(pp)

                }

                setTimeout(function () {
                    myChartss.setOption(_this.option,true);
                    mainPiess.setOption(_this.optionPie,true);
                }, 200);

            }else{
                _this.$message({
                    message: '数据统计分析失败！',
                    type: 'error'
                });
            }


        });
        //待办事项初始化
        $.post("/home/purchase_orders/selectOrdersByUser",
            '',
            function (data) {
                //初始化列表项
                 _this.strs.sqNum=data.data.purchaseOrders.length;
            });
        $.post("/home/purchase_orders/selectOrdersByCreateUser",
            {"type":"待审核"},
            function (data) {
                //初始化列表项
                _this.strs.dshNum= data.data.purchaseOrders.length;
            });
        $.post("/home/purchase_orders/selectOrders4Quotation",
            '',
            function (data) {
                //初始化列表项
                _this.strs.dxjNum = data.data.purchaseOrders.length;
            });

        $.post("/home/quote_or_compare/selectAllByUserId_", "", function (data) {
            _this.strs.dqrNum = data.data.quoteOrCompare.length;
        });
        $.post("/home/purchase_orders/selectEnterOrders4Quotation",
            '',
            function (data) {
                //初始化列表项
                _this.strs.dwcNum = data.data.purchaseOrders.length;
            });
        $.post("/home/merchant/selectNoCutByCreateUser",
            '',
            function (data) {
                //初始化商家
                _this.strs.dshsjNum= data.data.shopDataList.length;
            });


        // $.post("/home/purchase_orders/selectMemorandInUniting", "", function (data) {
        //     _this.strs.htNum = data.data.purchaseOrders.length;
        //
        // });
        // _this.strs.zsNum=Number(_this.strs.tzsNum)+Number( _this.strs.htNum);
         _this.strs.zsNum=Number(_this.strs.tzsNum);
    }
});

var myChartss = echarts.init(document.getElementById('pieChart'));
//图形实例
var mainPiess = echarts.init(document.getElementById('histogram'));
// 使用刚指定的配置项和数据显示图表。